<style lang="scss" scoped>
@import "@/styles/mixins.scss";
.xjw-capsule {
  .is-fixed {
    position: fixed;
    width: 100%;
    left: 0;
    top: 0;
    z-index: 100;
    @include global-type-color;
    transition: all 0.2s linear;
    &--none {
      background: none;
    }
    &--white {
      background: #fff;
    }
    &--base {
      background: $base-color;
    }
    .nav {
      position: absolute;
      width: 100%;
      height: 100%;
      display: flex;
      color: $f303133;
      box-sizing: border-box;
      align-items: center;
      padding-left: 14upx;
      &.is-shadow {
        box-shadow: 0 10upx 28upx 0 rgba(240, 247, 247, 1);
      }
      .nav_left {
        font-size: 34upx;
        display: flex;
        align-items: center;
      }
      .nav_title {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }
}
</style>
<template>
  <view class="xjw-capsule" :style="{ height: height + 'px' }">
    <view :class="isFixedClass" :style="{ height: height + 'px' }">
      <view
        class="nav"
        :class="{ 'is-shadow': isShadow }"
        :style="{ 'padding-top': statusBarHeight + 'px' }"
        v-if="isNav"
      >
        <view class="nav_left">
          <view
            class="nav_left-back xjw-weixin_fanhuishangye iconfont"
            @tap="back"
          >
          </view>
        </view>
        <view class="nav_title"> {{ title }} </view>
      </view>
    </view>
  </view>
</template>
<script lang="ts">
import Vue, { PropType } from "vue";
import { Component, Emit, Prop } from "vue-property-decorator";
import { Ttype } from "../types/type";

@Component
export default class Index extends Vue {
  @Prop({ type: Number }) bottom;
  @Prop({ type: String as PropType<Ttype | "base">, default: "primary" }) type;
  @Prop({ type: Boolean, default: false }) isNav;
  @Prop({ type: String, default: "标题" }) title;
  @Prop({ type: Boolean, default: true }) isShadow;

  @Emit()
  updateBottom(bottom: number) {
    this.$emit("update:bottom", bottom);
  }

  statusBarHeight: number = 0;

  get isFixedClass() {
    return `is-fixed is-fixed--${this.type}`;
  }

  created() {
    this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  }

  get height(): number {
    let bottom: number = 0;
    //#ifdef MP-WEIXIN
    bottom = uni.getMenuButtonBoundingClientRect().bottom;
    //#endif
    /**
     * fix:固定的时候添加一个胶量底部7的间距
     */
    const px7 = uni.upx2px(14);
    this.updateBottom(bottom + px7);
    return bottom + px7;
  }

  back() {
    this.$emit("clickBack");
  }
}
</script>
